"""
@Author：十
@Time：2024/6/27 10:12
@FileName：GainsCalculateThread.py
@Description：计时器返回秒薪计算结果
"""
import datetime

from PyQt5.QtCore import QObject, pyqtSignal, QTimer


class GainsCalculateThread(QObject):
    Signal_Get_Gains = pyqtSignal(object)
    Signal_Transmit_Gains = pyqtSignal(object)

    def __init__(self, parent=None):

        super(GainsCalculateThread, self).__init__()

        self.sec_gain = 0
        self.parent = parent



    def GetSecGain(self, sec_gain):
        self.sec_gain = sec_gain

    def run(self):
        try:
            print('running Gains Calculate Thread')
            self.timer = QTimer()
            self.timer.timeout.connect(self.Current_Gains)
            self.timer.start(1000)

        #     current_time = datetime.datetime.now()
        #     clock_9 = datetime.datetime.now().replace(hour=9, minute=0, second=0, microsecond=0)
        #     clock_14 = datetime.datetime.now().replace(hour=14, minute=0, second=0, microsecond=0)
        #     morning_work = (current_time - clock_9)
        #     if current_time > clock_14:
        #         afternoon_work = current_time - clock_14
        #         work_time = afternoon_work + morning_work
        #     else:
        #         work_time = morning_work
        #     work_time = work_time.total_seconds()
        #     gain = (float(work_time) * self.sec_gain)
        #     gain = round(gain, 2)
        #     print('Current Gain:', gain)
        #     self.Signal_Transmit_Gains.emit(gain)
        except Exception as e:
            print(e)

    def Current_Gains(self):
        try:
            current_time = datetime.datetime.now()
            clock_9 = datetime.datetime.now().replace(hour=9, minute=0, second=0, microsecond=0)
            clock_14 = datetime.datetime.now().replace(hour=14, minute=0, second=0, microsecond=0)
            morning_work = (current_time - clock_9)
            if current_time > clock_14:
                afternoon_work = current_time - clock_14
                work_time = afternoon_work + morning_work
            else:
                work_time = morning_work
            work_time = work_time.total_seconds()
            gain = work_time * self.sec_gain
            gain = round(gain, 2)
            # print('Current Gain:', gain)
            self.timer.start(1000)
            self.Signal_Transmit_Gains.emit(gain)
            # self.Signal_Transmit_Gains.emit(gain)
        except Exception as e:
            print(e)
